//任务单列表页面
//  ZSBWorkOrderViewController.m
//  HCNewGoldFinger
//
//  Created by hugh on 16/4/4.
//  Copyright © 2016年 zjhcsoftios. All rights reserved.
//

#import "ZSBWorkOrderViewController.h"
#import "ZSBMyRewardViewCell.h"
#import "ISeeUserInfoModel.h"
#import "DatePickerView.h"
#import "MJRefresh.h"
#import "NewMissonListController.h"
#import <BlocksKit/UIView+BlocksKit.h>
#import "NewLoveMarketTimeFilterView.h"
#import <MJExtension/MJExtension.h>
#import "ZSBSearchModel.h"
#import <Masonry/Masonry.h>
#import "UIColor+Ex.h"
#import "NMarketTap.h"
#import "UIViewController+GetBundle.h"
#import "SVProgressHUD.h"
#import "iSeeNetworkRequest.h"
#import "NetworkAddress.h"
#import "ZSBWorkOrderRightMenuView.h"
#import "UIViewController+GetBundle.h"

#define iSEESCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define iSEESCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@interface ZSBWorkOrderViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UIScrollViewDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dateList;

@property (nonatomic, strong) ZSBWorkOrderRightMenuView *muneView;

@property (nonatomic, assign) NSInteger isBillChangeRole;

@property (nonatomic, strong) UIView *footerView;

@property (nonatomic, strong) UISearchBar *searchBar;


@property (nonatomic, copy) NSString *key;

@property (nonatomic, strong) UILabel *scopeLab;

@property (nonatomic, strong) UILabel *addressLab;

@property (nonatomic, strong) UIView *cView;

@property (nonatomic,strong) UIButton *button;
//菊花
@property (nonatomic, strong) UIActivityIndicatorView *activeView;
//菊花
@property (nonatomic, strong) UIView *blackView;
//搜索框显示和隐藏
@property (nonatomic, assign)BOOL searchshow;
/**
 *  开始日期
 */
@property (nonatomic, copy)NSString *startdate;
/**
 *  结束日期
 */
@property (nonatomic, copy)NSString *enddate;
/**
 *  日期选择器(是否显示问题)
 */
@property(nonatomic,strong)UIView *dateshowview;
@property(nonatomic,strong)UIView *headview;
//响应时间参数
@property (nonatomic, copy)NSString *datestr;
//地图相关

@property (nonatomic, copy)UIButton *mapButton;


@property(nonatomic,strong)UIView *back;

//时间选择view
@property (nonatomic, strong) UIView *timeFilter;
//时间选择数据列表
@property (nonatomic, strong) NSMutableArray *timeFilterList;
//时间选择选项
@property (nonatomic, strong) NSDictionary *timeFilterDic;

@end



@implementation ZSBWorkOrderViewController


-(void)tapAction:(UITapGestureRecognizer*)sender{

    [sender.view removeFromSuperview];
    
}

-(void)startDate:(NSString *)str endDate:(NSString *)str1{
    [_back removeFromSuperview];
    _startdate = str;
    _enddate = str1;
    _datestr =[self nowtime];
    if ([self.logId isEqualToString:@"526"]) {
        [self.tableView.mj_header beginRefreshing];

    }else{
        [self.tableView.mj_header beginRefreshing];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [SVProgressHUD dismiss];
    if ([_logId isEqualToString:@"526"]) {
//        [_mapView viewWillDisappear];
//        _mapView.delegate = nil; // 不用时，置nil
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if ([_logId isEqualToString:@"526"]) {
//        [_mapView viewWillAppear];
//        _mapView.delegate = self;
        [self.tableView.mj_header beginRefreshing];

    }else{
        if (_reload.length) {
            
             [self.tableView.mj_header beginRefreshing];
            _reload = nil;
        }
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    _dateList = [NSMutableArray array];
    
    _headview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, iSEESCREEN_WIDTH, 94)];
    _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, iSEESCREEN_WIDTH, 50)];
    _searchBar.delegate = self;
    
    [self initFilterView];
    
    [_headview addSubview:_searchBar];
    [_headview addSubview:_timeFilter];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, iSEESCREEN_WIDTH, self.view.bounds.size.height) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = 70;
    _tableView.tableHeaderView = _headview;
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
    _headview.hidden = NO;
    
    if ([_logId isEqualToString:@"526"]) {
//        [self qiangdanchimapview];
    }
    
    __weak ZSBWorkOrderViewController *wself = self;
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [wself getList];
    }];
    
    
    self.searchBar.showsCancelButton = YES;
    _muneView = [[ZSBWorkOrderRightMenuView alloc] init];
    //菜单接口
    __weak __typeof(self)weakSelf = self;
    _muneView.clickBlock = ^(ZPMenuModel *model){
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.datestr =[strongSelf nowtime];
        strongSelf.logId = [NSString stringWithFormat:@"%@",model.logId];
        [strongSelf.dateList removeAllObjects];
        [strongSelf.tableView reloadData];
        //        [strongSelf.footerView removeAllSubviews];
        [strongSelf.footerView removeFromSuperview];
        [strongSelf.dateshowview removeFromSuperview];
        strongSelf.title = model.name;

        if (![[NSString stringWithFormat:@"%@",model.logId] isEqualToString:@"526"]) {

            [strongSelf getList];

            [strongSelf.view addSubview:strongSelf.button];
        }else{
            [strongSelf.button removeFromSuperview];
//            [strongSelf qiangdanchimapview];
            [strongSelf getList];
            [strongSelf.footerView removeFromSuperview];
        }
    };
    if ([_type isEqualToString:@"1"]) {
        
    }else {
        
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[self getImageFromBundle:@"list"] style:UIBarButtonItemStylePlain target:self action:@selector(showMuneView)];
    }

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getSuccessNotion:) name:@"GET_INTERFACE_ACCESS_SUCCESSFUL" object:nil];
    
    _timeFilterList = [NSMutableArray array];
    [self getTimeFilterList];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



//任务单请求url
- (void)getList
{
    
    
    _datestr =[self nowtime];
    
    [_cView removeFromSuperview];
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    

    //日期选择
    if (_startdate.length) {
        [params setObject:_startdate forKey:@"startDate"];
    }
    if (_enddate.length) {
        [params setObject:_enddate forKey:@"endDate"];
    }
    if (_orderOpenSource.length) {
        [params setObject:_orderOpenSource forKey:@"orderOpenSource"];
    }
    
    if (self.mapDic) {
        if ([self.mapDic[@"isShow"] integerValue] == 1) {
            if (self.mapDic[@"latitude"]) {
                [params setObject:self.mapDic[@"latitude"] forKey:@"latitude"];
            }
            if (self.mapDic[@"longitude"]) {
                [params setObject:self.mapDic[@"longitude"] forKey:@"longitude"];
            }
            if (self.mapDic[@"Scope"]) {
                [params setObject:self.mapDic[@"Scope"] forKey:@"length"];
            }
        }
    }
    if (_timeFilterDic.count > 0) {
        [params setValuesForKeysWithDictionary:_timeFilterDic];
    }
    
    if ([_type isEqualToString:@"1"]) {
        if (_labelId.length) {
            [params setObject:self.labelId forKey:@"labelId"];
        }
        
        if (_key.length) {
            [params setObject:_key forKey:@"keywords"];
        }
        
        [iSeeNetworkRequest getWithHeaderUrl:[NSString stringWithFormat:@"%@%@", NMarketMainUrl, GetOrderProjectListFromTag] params:params success:^(id object) {
            NSDictionary *body = object[@"body"];
            self.isBillChangeRole = [body[@"isBillChangeRole"] integerValue];
            
            NSArray *result = body[@"result"];
            [self.dateList removeAllObjects];
            for (NSDictionary *dic in result) {
                [self.dateList addObject:[ZSBMyRewardInfo modelObjectWithDictionary:dic]];
            }
            //待支付加载
            
            [self.tableView reloadData];
            self.mapDic = nil;
            [self.tableView.mj_header endRefreshing];
        } failure:^(NSError *error) {
            self.mapDic = nil;
            [SVProgressHUD showErrorWithStatus:error.userInfo[@"responseObject"][@"msg"]];
            [self.tableView.mj_header endRefreshing];
        }];
        
    }else {
        

        if (_key.length) {
            [params setObject:_key forKey:@"key"];
        }
        
        if (_logId.length) {
            [params setObject:self.logId forKey:@"logId"];
        }
        
        
        [iSeeNetworkRequest getWithHeaderUrl:[NSString stringWithFormat:@"%@%@", NMarketMainUrl, GetOrderProjectList] params:params success:^(id object) {
            NSDictionary *body = object[@"body"];
            self.isBillChangeRole = [body[@"isBillChangeRole"] integerValue];
            NSArray *result = body[@"result"];
            [self.dateList removeAllObjects];
            for (NSDictionary *dic in result) {
                [self.dateList addObject:[ZSBMyRewardInfo modelObjectWithDictionary:dic]];
            }
            self.mapDic = nil;
            [self.tableView.mj_header endRefreshing];
            [self.tableView reloadData];
        } failure:^(NSError *error) {
            self.mapDic = nil;
            [self.tableView.mj_header endRefreshing];
        }];
    }
    
}

//显示菜单
- (void)showMuneView
{
//    日期选择器显示的时候 如果没有点确定或者取消 会一直显示,执行其他操作需要先移除
    [_dateshowview removeFromSuperview];
    [_muneView show];
}
//section imageview显示状态//11111111
-(void)HeadViewTap:(NMarketTap *)tap{
    _datestr =[self nowtime];
    if (tap.selectRow < _dateList.count) {
        ZSBMyRewardInfo *info = _dateList[tap.selectRow];
            
        NewMissonListController *viewCtrl = [[UIStoryboard storyboardWithName:@"ZPaiyingxiao" bundle:[self getBundle]] instantiateViewControllerWithIdentifier:@"NewMissonListController"];
        viewCtrl.logId = self.logId;
        viewCtrl.projectId = info.projectId;
        viewCtrl.startdate = _startdate;
        viewCtrl.enddate = _enddate;
        viewCtrl.type = _type;
        viewCtrl.labelId = _labelId;
        viewCtrl.key = _key;
        viewCtrl.timeFilterList = _timeFilterList;
        viewCtrl.timeFilterDic = _timeFilterDic;
        viewCtrl.title = self.title;
        [self.navigationController pushViewController:viewCtrl animated:YES];

    }
}
//cell打开和关闭
- (void)selectButtonClick:(UIButton *)button
{
    button.selected = !button.selected;
    ZSBMyRewardInfo *info = _dateList[button.tag];
    info.isSelect = button.selected;
    for (ZSBMyRewardInfo *myInfo in info.result) {
        myInfo.isSelect = info.isSelect;
    }
    for (ZSBMyRewardInfo *info in _dateList) {
        if (button.tag != [_dateList indexOfObject:info]) {
            info.isSelect = NO;
        }
        for (ZSBMyRewardInfo *myRewardInfo in info.result) {
            if (button.tag != [_dateList indexOfObject:info]) {
                myRewardInfo.isSelect = NO;
            }
        }
    }
    [_tableView reloadData];
}

-(NSString *)allSelectIds
{
    NSString *string = @"";
    for (ZSBMyRewardInfo *info1 in _dateList) {
        for (ZSBMyRewardInfo *info in info1.result) {
            if (info.isSelect) {
                string = [NSString stringWithFormat:@"%@,%@",string,info.orderId];
            }
        }
    }
    if (string.length>0) {
        string = [string substringWithRange:NSMakeRange(1, string.length-1)];
    }
    return string;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if ([_logId isEqualToString:@"526"]&&_dateList.count) {
        return  _dateList.count + 1;
    }
    return _dateList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == _dateList.count) {
        return 300;
    }
    return 70;
}
//sectionview
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    if ( section <  _dateList.count) {
        ZSBMyRewardInfo *info = _dateList[section];
        CGFloat height = [self tableView:self.tableView heightForHeaderInSection:section];
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, height)];
        headerView.backgroundColor = [UIColor whiteColor];
        CGFloat top = 10;
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, top, tableView.bounds.size.width - 85, 20)];
        titleLabel.font = [UIFont systemFontOfSize:12];
        titleLabel.textColor = [UIColor colorWithHexString:@"333333"];
        titleLabel.text = info.name;
        [headerView addSubview:titleLabel];
        
        
        UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, titleLabel.frame.origin.y + titleLabel.bounds.size.height, titleLabel.bounds.size.width, 17)];
        contentLabel.font = [UIFont systemFontOfSize:12];
        contentLabel.textColor = [UIColor colorWithHexString:@"888888"];
        contentLabel.text = [NSString stringWithFormat:@"%@----%@",info.createDate,info.availableDate];
        [headerView addSubview:contentLabel];
        
        UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, contentLabel.frame.origin.y + contentLabel.bounds.size.height, contentLabel.bounds.size.width, 17)];
        countLabel.font = [UIFont systemFontOfSize:12];
        countLabel.textColor = [UIColor colorWithHexString:@"888888"];
        countLabel.text = [NSString stringWithFormat:@"共%li条",(long)info.orderCount];
        [headerView addSubview:countLabel];
        
        NMarketTap *tap =[[NMarketTap alloc] initWithTarget:self action:@selector(HeadViewTap:)];
        tap.selectRow =section;
        
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(8, 25, 25, 25)];
        image.image = [self getImageFromBundle:@"button_to_right"];
        [headerView addSubview:image];
        //问号按钮
        if (info.desc.length > 0) {
            
            UIButton *helpButton = [[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width - 40, 10, 25, 25)];
            [helpButton setImage:[self getImageFromBundle:@"buttonhelp"] forState:UIControlStateNormal];

            helpButton.titleLabel.hidden = YES;
            [helpButton addTarget:self action:@selector(openbuttonHelp:) forControlEvents:UIControlEventTouchUpInside];
            helpButton.tag = section;
            headerView.userInteractionEnabled = YES;
            [headerView addSubview:helpButton];
        }
//        if (info.isOpen) {
//            image.image = [self getImageFromBundle:@"button_to_bottom"];
//            tap.selected = YES;
//        }else{
//            image.image = [self getImageFromBundle:@"button_to_right"];
//
//            tap.selected = NO;
//        }
        //一键接单
//        if ([_logId isEqualToString:@"520"]||[_logId isEqualToString:@"537"]||[_logId isEqualToString:@"538"]) {
//            UIButton *oneselectButton = [[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width - 100, height - 28, 40, 18)];
//            [oneselectButton setTitle:@"全接" forState:UIControlStateNormal];
//            [oneselectButton addTarget:self action:@selector(selectoneButtonClick:) forControlEvents:UIControlEventTouchUpInside];
//            oneselectButton.tag = 300 + section;
//            oneselectButton.titleLabel.font = [UIFont systemFontOfSize:11];
//            [oneselectButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//            oneselectButton.layer.borderColor = [[UIColor colorWithWhite:0.162 alpha:1.000] CGColor];
//            oneselectButton.layer.borderWidth = 0.5f;
//            //给按钮设置弧度,这里将按钮变成了圆形
//            oneselectButton.layer.cornerRadius = 3.0f;
//
//            oneselectButton.layer.masksToBounds = YES;
//            [headerView addSubview:oneselectButton];
//            //竖条
//            UIView *lineshu = [[UIView alloc] initWithFrame:CGRectMake(tableView.bounds.size.width - 55, height - 28, 0.5, 18)];
//            lineshu.backgroundColor = [UIColor blackColor];
//            [headerView addSubview:lineshu];
//        }
        
      
        

        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, height-0.5, tableView.bounds.size.width, 0.5)];
        line.backgroundColor = [UIColor colorWithHexString:@"cccccc"];
        [headerView addSubview:line];
        [headerView addGestureRecognizer:tap];
        return headerView;
    }{
        return  _cView;
    }
}

//问号按钮的实现方法
-(void)openbuttonHelp:(UIButton *)btn{
    
    ZSBMyRewardInfo *info = _dateList[btn.tag];
    NSString *str =[NSString stringWithFormat:@"活动名称:%@\n \n活动内容:%@",info.topicName,info.desc];
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:str preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction: [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [self presentViewController:alert animated:YES completion:nil];
    //工单活动列表埋点
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == _dateList.count) {
        return 0;
    }
    ZSBMyRewardInfo *info = _dateList[section];
    if (info.isOpen == NO) {
        return 0;
    }
    
    if (info.orderCount > 5) {
        return info.result.count+1;
    }else{
        return info.result.count;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row < 5) {
        ZSBMyRewardInfo *info = _dateList[indexPath.section];
        if (info.result.count >indexPath.row) {
            ZSBMyRewardInfo *myRewardInfo = info.result[indexPath.row];
            return [ZSBMyRewardViewCell heightForCell:myRewardInfo.content];
        }
        return 0;
        
    }else{
        return 40;
    }
}
//待处理等工单的cell显示
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row < 5) {
        NSString *cellName = @"ZSBMyRewardViewCell";
        ZSBMyRewardViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
        if (cell == nil) {
            //待处理cell
            cell = [[ZSBMyRewardViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
        }
        cell.indexPath = indexPath;
        if (indexPath.section <_dateList.count&&_dateList.count != 0) {
        ZSBMyRewardInfo *info = _dateList[indexPath.section];
            if (indexPath.row < info.result.count) {
        ZSBMyRewardInfo *myRewardInfo = info.result[indexPath.row];
        cell.myRewardInfo = myRewardInfo;
        cell.needChoose = YES;
        cell.content = myRewardInfo.content;
        cell.moneyLabel.text = myRewardInfo.commission;
        [cell.statusLabel setTitle:myRewardInfo.status forState:UIControlStateNormal];
        cell.chooseButton.selected = myRewardInfo.isSelect;
            }}
        return cell;
    }else{
        NSString *cellName = @"ZSBMyRewardViewCellMore";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
            cell.backgroundColor = [UIColor colorWithHexString:@"EFEFF4"];
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 40)];
            label.font = [UIFont systemFontOfSize:13];
            label.textColor = [UIColor lightGrayColor];
            label.textAlignment = NSTextAlignmentCenter;
            label.text = @"查看更多";
            [cell.contentView addSubview:label];
            UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 40 - 0.5, self.view.bounds.size.width, 0.5)];
            line.backgroundColor = [UIColor colorWithHexString:@"cccccc"];
            [cell.contentView addSubview:line];
        }
        return cell;
    }
}
//cell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    ZSBMyRewardInfo *info = _dateList[indexPath.section];
//    if (indexPath.row < 5) {
//        ZSBMyRewardInfo *myRewardInfo = info.result[indexPath.row];
//
//        NewMissonListDetailController *ctrl = [[UIStoryboard storyboardWithName:@"ZPaiyingxiao" bundle:[self getBundle]] instantiateViewControllerWithIdentifier:@"NewMissonListDetailController"];
//        ctrl.ordorId = myRewardInfo.orderId;
//        ctrl.isOrdorListEnter = YES;
//        ctrl.logId = self.logId;
//        [self.navigationController pushViewController:ctrl animated:YES];
//
//    }else{
//
//        NewMissonListController *viewCtrl = [[UIStoryboard storyboardWithName:@"ZPaiyingxiao" bundle:[self getBundle]] instantiateViewControllerWithIdentifier:@"NewMissonListController"];
//        viewCtrl.logId = self.logId;
//        viewCtrl.projectId = info.projectId;
//        viewCtrl.startdate = _startdate;
//        viewCtrl.enddate = _enddate;
//        viewCtrl.title = self.title;
//        viewCtrl.timeFilterList = _timeFilterList;
//        viewCtrl.timeFilterDic = _timeFilterDic;
//
//        if ([_logId isEqualToString:@"526"] ) {
//            viewCtrl.title =@"抢单池";
//        }else if ([_logId isEqualToString:@"548"]) {
//            viewCtrl.title = @"抢单池组";
//        }
//        [self.navigationController pushViewController:viewCtrl animated:YES];
//    }
}

- (void)cell:(id)cell_ didSelectAtIndexPath:(NSIndexPath *)indexPath buttonIndex:(NSInteger)index   
{
    
    for (ZSBMyRewardInfo *info in _dateList) {
        if (indexPath.section != [_dateList indexOfObject:info]) {
            info.isSelect = NO;
        }
        for (ZSBMyRewardInfo *myRewardInfo in info.result) {
            if (indexPath.section != [_dateList indexOfObject:info]) {
                myRewardInfo.isSelect = NO;
            }
        }
    }
    [_tableView reloadData];
}

////地图开关
//- (void)swithOnClick:(UISwitch *)switchon
//{
//    if (switchon.on == YES) {
//        [self.mapDic setObject:[NSNumber numberWithInteger:1] forKey:@"isShow"];
//    }else{
//        [self.mapDic setObject:[NSNumber numberWithInteger:0] forKey:@"isShow"];
//    }
//}
////地图界面
//-(void)qiangdanchimapview{
//    [_tableView setFrame:CGRectMake(0, 0, iSEESCREEN_WIDTH, self.view.bounds.size.height -64 - 50)];
//    if (_cView == nil) {
//        _cView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 240)];
//        _cView.backgroundColor = [UIColor whiteColor];
////        [self.tableView.tableFooterView  addSubview:_cView];
//        UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, iSEESCREEN_WIDTH, 40)];
//        bView.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
//        [_cView addSubview:bView];
//
//        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, iSEESCREEN_WIDTH-20, 40)];
//        label.font = [UIFont systemFontOfSize:16];
//        label.textColor = [UIColor blackColor];
//        label.text = @"是否选择定位";
//        [_cView addSubview:label];
//
//        _switchOn = [[UISwitch alloc] initWithFrame:CGRectMake(iSEESCREEN_WIDTH - 70, 5, 60, 30)];
//
//        _switchOn.tintColor = [UIColor whiteColor];
//        [_switchOn addTarget:self action:@selector(swithOnClick:) forControlEvents:UIControlEventValueChanged];
//
//        [_cView addSubview:_switchOn];
//
//        if (_mapView == nil) {
//            _mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(10, 50, iSEESCREEN_WIDTH - 20, 140)];
//            _mapView.delegate = self;
//        }
//        [_cView addSubview:_mapView];
//
//        _mapButton = [[UIButton alloc] initWithFrame:_mapView.frame];
//        [_mapButton addTarget:self action:@selector(showMapView:) forControlEvents:UIControlEventTouchUpInside];
//        [_cView addSubview:_mapButton];
//
//        _addressLab = [[UILabel alloc] initWithFrame:CGRectMake(10, _mapView.frame.origin.x + _mapView.bounds.size.height, _cView.bounds.size.width-20, 20)];
//        _addressLab.font = [UIFont systemFontOfSize:15];
//        _addressLab.textColor = [UIColor blackColor];
//        _addressLab.numberOfLines = 2;
//        [_cView addSubview:_addressLab];
//
//        _scopeLab = [[UILabel alloc] initWithFrame:CGRectMake(10, _addressLab.frame.origin.x + _addressLab.bounds.size.height, _cView.bounds.size.width-20, 20)];
//        _scopeLab.font = [UIFont systemFontOfSize:15];
//        _scopeLab.textColor = [UIColor blackColor];
//        _scopeLab.numberOfLines = 2;
//        [_cView addSubview:_scopeLab];
//
//    }
//    [self.tableView.tableFooterView  addSubview:_cView];
//
//    if (self.mapDic)
//    {
//        NSNumber * isShow = [self.mapDic objectForKey:@"isShow"];
//        if (isShow && [isShow boolValue])
//        {
//            _switchOn.on = YES;
//        }
//    }
//
//    if (self.mapDic) {
//        NSInteger isShow = [self.mapDic[@"isShow"] integerValue];
//        if (isShow == 1) {
//            _switchOn.on = YES;
//        }
//        if (self.mapDic[@"latitude"]) {
//            [self addMapPoint];
//
//
//            if (self.mapDic[@"address"]) {
//                _addressLab.text = self.mapDic[@"address"];
//            }else{
//                _addressLab.text = @"无法解析地址";
//            }
//
//        }
//        if (self.mapDic[@"Scope"]) {
//
//            if (self.mapDic[@"Scope"]) {
//                _scopeLab.text = [NSString stringWithFormat:@"范围:%@米",self.mapDic[@"Scope"]];
//            }else{
//                _scopeLab.text = @"默认范围";
//            }
//            CLLocationCoordinate2D coordinate;
//            coordinate.latitude = [self.mapDic[@"latitude"] doubleValue];
//            coordinate.longitude = [self.mapDic[@"longitude"] doubleValue];
//
//            _circleTargePlace=[BMKCircle circleWithCenterCoordinate:coordinate radius:[self.mapDic[@"Scope"] doubleValue]];
//            [_mapView addOverlay:_circleTargePlace];
//
//            CGFloat n = [self.mapDic[@"Scope"] doubleValue]/100000.0;
//
//            CLLocationCoordinate2D topLeftCoord;
//            topLeftCoord.latitude = coordinate.latitude+n;
//            topLeftCoord.longitude = coordinate.longitude-n;
//
//            CLLocationCoordinate2D bottomRightCoord;
//            bottomRightCoord.latitude = coordinate.latitude-n;
//            bottomRightCoord.longitude = coordinate.longitude+n;
//
//            for(id<BMKAnnotation> annotation in _mapView.annotations) {
//                topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
//                topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);
//                bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
//                bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
//            }
//
//            BMKCoordinateRegion region;
//            region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
//            region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
//            region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1;
//
//            // Add a little extra space on the sides
//            region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1;
//
//            region = [_mapView regionThatFits:region];
//            [_mapView setRegion:region animated:YES];
//        }
//    }
//    [_tableView reloadData];
////}

//- (void) addMapPoint
//{
//    [_mapView removeAnnotations:_mapView.annotations];
//    if (self.mapDic[@"latitude"])
//    {
//        CLLocationCoordinate2D coordinate;
//        coordinate.latitude = [self.mapDic[@"latitude"] doubleValue];
//        coordinate.longitude = [self.mapDic[@"longitude"] doubleValue];
//
//        if (_pointAnnotation == nil) {
//            _pointAnnotation = [[BMKPointAnnotation alloc]init];
//            _pointAnnotation.title = @"";
//            _pointAnnotation.coordinate = coordinate;
//            [_mapView addAnnotation:_pointAnnotation];
//        }
//    }
//}
//- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay
//{
//    if ([overlay isKindOfClass:[BMKCircle class]]) {
//        BMKCircleView *_circleView=[[BMKCircleView alloc] initWithCircle:overlay];
//        _circleView.fillColor =  [UIColor colorWithRed:137/255.0 green:170/255.0 blue:213/255.0 alpha:0.2];
//        _circleView.strokeColor = [UIColor colorWithRed:117/255.0 green:161/255.0 blue:220/255.0 alpha:0.8];
//        _circleView.lineWidth=2.0;
//        return _circleView;
//    }
//    return nil;
//}

//- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
//{
//    //    //普通annotation
//    if (annotation == _pointAnnotation) {
//        NSString *AnnotationViewID = @"renameMark";
//        BMKPinAnnotationView *annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
//        if (annotationView == nil) {
//            annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
//            // 设置颜色
//            annotationView.pinColor = BMKPinAnnotationColorPurple;
//            // 从天上掉下效果
//            annotationView.animatesDrop = NO;
//            // 设置可拖拽
//            annotationView.draggable = NO;
//
//            [annotationView setImage:[self getImageFromBundle:@"map_marker"]];
//
//        }
//        return annotationView;
//    }
//    return nil;
//
//}
- (void)showMapView:(UIButton *)button
{
//    HCNewMapPointSelectBoard_iPhone *viewCtrl = [[HCNewMapPointSelectBoard_iPhone alloc] init];
//    viewCtrl.mapDic = self.mapDic;
//    if (_switchOn.on) {
//        viewCtrl.isShow = 1;
//    }else{
//        viewCtrl.isShow = 0;
//    }
//    viewCtrl.successBlock = ^(id object){
//        self.mapDic = object;
//
//
//        if (!_mapView.delegate) {
//            _mapView.delegate = self;
//        }
//
//        [_mapView removeAnnotations:_mapView.annotations];
//
//        if (self.mapDic[@"address"]) {
//            _addressLab.text = self.mapDic[@"address"];
//        }else{
//            _addressLab.text = @"无法解析地址";
//        }
//
//        if (self.mapDic[@"Scope"]) {
//            _scopeLab.text = [NSString stringWithFormat:@"范围:%@米",self.mapDic[@"Scope"]];
//        }else{
//            _scopeLab.text = @"默认范围";
//        }
//
//        if (_circleTargePlace) {
//            [_mapView removeOverlay:_circleTargePlace];
//            _circleTargePlace = nil;
//        }
//        CLLocationCoordinate2D coordinate;
//        coordinate.latitude = [self.mapDic[@"latitude"] doubleValue];
//        coordinate.longitude = [self.mapDic[@"longitude"] doubleValue];
//
//        [self addMapPoint];
//
//        _circleTargePlace=[BMKCircle circleWithCenterCoordinate:coordinate radius:[self.mapDic[@"Scope"] doubleValue]];
//        [_mapView addOverlay:_circleTargePlace];
//
//        CGFloat n = [self.mapDic[@"Scope"] doubleValue]/100000.0;
//
//        CLLocationCoordinate2D topLeftCoord;
//        topLeftCoord.latitude = coordinate.latitude+n;
//        topLeftCoord.longitude = coordinate.longitude-n;
//
//        CLLocationCoordinate2D bottomRightCoord;
//        bottomRightCoord.latitude = coordinate.latitude-n;
//        bottomRightCoord.longitude = coordinate.longitude+n;
//
//        for(id<BMKAnnotation> annotation in _mapView.annotations) {
//            topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
//            topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);
//            bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
//            bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
//        }
//
//        BMKCoordinateRegion region;
//        region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
//        region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
//        region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1;
//
//        // Add a little extra space on the sides
//        region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1;
//
//        region = [_mapView regionThatFits:region];
//        [_mapView setRegion:region animated:YES];
//    };
//    [self.navigationController pushViewController:viewCtrl animated:YES];
}

- (void)setMapDic:(NSMutableDictionary *)mapDic
{
    _mapDic = [mapDic mutableCopy];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    searchBar.text = nil;
    [_dateList removeAllObjects];
    _key =nil;
    [searchBar resignFirstResponder];
    if (![_logId isEqualToString:@"526"]) {
        [self getList];
//        [self getworkList];

    }else{
//        [self getworkList];
        [self getList];

    }
}
//搜索框点击事件
- (void)searchBarDidEndSelect:(UIButton *)button
{
    
    [_searchBar resignFirstResponder];
}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    _key = searchText;
}
//搜索字段
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [_dateList removeAllObjects];
//    _key = searchBar.text;
    
    if ([_logId isEqualToString:@"526"]) {
//        [self  getworkList];
        [self getList];

    }else{
        [self getList];
    }
    [_searchBar resignFirstResponder];
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
    //日期移除
    [_dateshowview removeFromSuperview];
}





-(void)Reload:(NSString *)reload{
    self.reload = reload;
    
}
//一键接单
-(void)selectoneButtonClick:(UIButton *)btn{
    UIAlertView *alertview =[[UIAlertView alloc] initWithTitle:@"提示" message:@"是否全部接单" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertview.tag = btn.tag;
    [alertview show];
    
}

//一键接单
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (_dateList.count) {
        if (alertView.tag != 1001) {
            if (buttonIndex == 1) {
                ZSBMyRewardInfo *info =_dateList[alertView.tag -300];
                NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
                [params setObject:info.projectId forKey:@"projectId"];
                [iSeeNetworkRequest getWithHeaderUrl:[NSString stringWithFormat:@"%@%@", NMarketMainUrl, BatchOrderListAcceptAndReject] params:params success:^(id object) {
                    [SVProgressHUD showSuccessWithStatus:@"接单成功"];
                
                    [self getList];
                } failure:^(NSError *error) {
                    [SVProgressHUD showErrorWithStatus:@"接单失败"];
                }];
            }
        }
    }
}

- (void)getSuccessNotion:(NSNotification *) note {
    
    [SVProgressHUD showSuccessWithStatus:[note.userInfo objectForKey:@"notiText"]];
    
}

- (void)getTimeFilterList {
    
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    if ([_type isEqualToString:@"1"]) {
        [parmas setObject:self.labelId forKey:@"labelId"];
    }
    
    [iSeeNetworkRequest getWithHeaderUrl:[NSString stringWithFormat:@"%@%@", NMarketMainUrl, GetOrderTimeFilter] params:parmas success:^(id object) {
        [self.timeFilterList addObjectsFromArray:[ZSBSearchModel mj_objectArrayWithKeyValuesArray:object[@"body"][@"result"]]];
    } failure:^(NSError *error) {
        
    }];
}

- (void)initFilterView {
    
    _timeFilter = [[UIView alloc] initWithFrame:CGRectMake(0, 50, iSEESCREEN_WIDTH, 44)];
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 43, iSEESCREEN_WIDTH, 1)];
    line.backgroundColor = [UIColor colorWithHexString:@"EAECEF"];
    [_timeFilter addSubview:line];
    _timeFilter.backgroundColor = [UIColor whiteColor];
    _timeFilterDic = [NSMutableDictionary dictionary];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @"时间筛选";
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = [UIColor colorWithHexString:@"444444"];
    [_timeFilter addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.timeFilter);
        make.left.mas_equalTo(self.timeFilter.mas_left).offset(15);
    }];
    
    UIImageView *image = [[UIImageView alloc] init];
    [image setImage:[self getImageFromBundle:@"ayx_timeFilter_Chevron_right"]];
    [_timeFilter addSubview:image];
    
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.timeFilter);
        make.right.mas_equalTo(self.timeFilter.mas_right).offset(-10);
    }];
    
    
    
    [_timeFilter bk_whenTapped:^{
        
        [UIView animateWithDuration:.25 animations:^{
            image.transform = CGAffineTransformMakeRotation(90 *M_PI / 180.0);
        }completion:^(BOOL finished) {
            
            CGRect rc = [self.timeFilter convertRect:self.timeFilter.bounds toView:self.view.window];
            
            CGPoint point = CGPointMake(rc.origin.x, rc.origin.y + rc.size.height);
            
            [NewLoveMarketTimeFilterView showNewLoveMarketTimeFilterView:self.view.window point:point timeFiterList:self.timeFilterList success:^(NSDictionary *selectTime) {
                self.timeFilterDic = selectTime;
                
                NSLog(@"%@", selectTime);
                
                [UIView animateWithDuration:.25 animations:^{
                    image.transform = CGAffineTransformIdentity;
                }];
                
                [self getList];
            } failure:^{
                [UIView animateWithDuration:.25 animations:^{
                    image.transform = CGAffineTransformIdentity;
                }];
            }];
            
            
        }];
        
        
        
        
    }];
}


//获取当前时间
- (NSString *)nowtime{
    NSDate *date = [NSDate date];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss:SSS"];
    NSString *datetime = [formatter stringFromDate:date];
    
    return datetime;
}

@end
